<template>
  <div>
    <r-search
      :searchForm="searchForm"
      :searchHandle="searchHandle"
      :searchData="searchData"
    />
    <r-table
      :isPagination="true"
      :tableData="tableData"
      :tableCols="tableCols"
      :tablePage="tablePage"
      @refresh="init()"
    ></r-table>
    <!-- <r-form :formRules="formRules" :formHandle="formHandle" :formData="formData" :formCols="formCols" ref="elForm" labelWidth="100px" dialogWidth="500px" :isHandle="true" /> -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchData: {
        orderNo: "",
        nickName: "",
        createdTime: ""
      },
      searchForm: [
        {
          type: "input",
          prop: "orderNo",
          placeholder: "Order Nnumber",
          width: 150
        },
        {
          type: "input",
          prop: "nickName",
          placeholder: "IC卡号",
          width: 150
        },
        {
          type: "date",
          prop: "createdTime",
          placeholder: "Submission Time",
          width: 170
        }
      ],
      searchHandle: [
        {
          label: "Search",
          type: "success",
          icon: "el-icon-search",
          handle: e => this.init()
        },
        {
          label: "Reset",
          icon: "el-icon-refresh-right",
          handle: e => this.searchFromReset()
        }
        // {
        //     label: "ExportExcel",
        //     icon: 'el-icon-download',
        //     type: "success",
        //     loading: false,
        //     handle: (that) => this.handleDownload(),
        // },
      ],
      tableData: [],
      tableCols: [
        {
          label: "Order Nnumber",
          prop: "orderNo"
          // theme: e => e.status ? 'primary' : 'danger', type: "tag",
        },
        {
          label: "Submission Time",
          prop: "createdTime"
        },
        {
          label: "IC卡号",
          prop: "cardNumber"
        },
        {
          label: "Recharge方式",
          prop: "channel",
          formatter: e =>
            e.channel == 0
              ? "线上"
              : e.channel == 1
              ? "线下"
              : e.channel == 2
              ? "系统Recharge"
              : ""
        },
        {
          label: "Recharge Amount",
          prop: "topupMoney"
        },
        {
          label: "Payment方式",
          prop: "pay_type",
          formatter: e =>
            e.payType == 1
              ? "WeChatPayment"
              : e.payType == 2
              ? "AlipayPayment"
              : e.payType == 3
              ? "现金"
              : ""
        },
        {
          label: "订单Status",
          prop: "state",
          theme: e => (e.state == 27 ? "primary" : "danger"),
          type: "tag",
          formatter: e =>
            e.state == 26
              ? "RechargeFailure"
              : e.state == 27
              ? "RechargeSuccess"
              : ""
        },
        {
          label: "Operations",
          type: "button",
          btnList: [
            {
              label: "Order Details",
              type: "primary",
              // isShow: e => e.orderId == '123' ? true : false,
              handle: row => this.goDetail(row.id)
            }
          ]
        }
      ],
      tablePage: { limit: 10, page: 1, total: 0 }
    };
  },
  components: {},
  computed: {},
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      let parm = { ...this.searchData, ...this.tablePage };
      let res = await this.api.rechargeList(parm);
      if (res) {
        this.tablePage.total = res.data.total;
        this.tableData = res.data.list;
      }
    },
    //查询
    elFormSubmit() {},
    goDetail(id) {
      this.$router.push({ path: "/order-ICardTopup_Detail", query: { id } });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          // if (j === 'connectedStatus') {
          //     return v[j] == 1 ? "Online" : "Offline"
          // } else if (j === 'status') {
          //     return v[j] == 1 ? "正常" : v[j] == 2 ? "设备维护中" : "Nonactivated"
          // } else {
          return v[j];
          // }
        })
      );
    }
  }
};
</script>
<style scoped lang="scss">
.el-icon-search {
  margin-right: 10px;
}
</style>
